create or replace function save_spongecity_upconfig(
	euid_ text,
	rain_wakeup_ smallint, rain_report_ smallint,
	norain_wakeup_ smallint, norain_report_ smallint,
	flow_pipe_ smallint, flow_height_ smallint,
	cod_interval_ smallint, cod_circle_ smallint, flow_cal_con_ smallint
) 
returns void as $$
declare
pk_of_euid integer;
begin
    select id into pk_of_euid from t_node_info2 where euid = euid_;
    if found then
		update t_spongecity_upconfig 
		set rain_wakeup = rain_wakeup_,
		rain_report = rain_report_,
		norain_wakeup = norain_wakeup_,
		norain_report = norain_report_,
		flow_pipe = flow_pipe_,
		flow_height = flow_height_,
		cod_interval = cod_interval_,
		cod_circle = cod_circle_,
		flow_cal_con = flow_cal_con_
		where euid = pk_of_euid;
		if not found then
			insert into t_spongecity_upconfig ( euid, 
				rain_wakeup, rain_report, norain_wakeup, norain_report, 
				flow_pipe, flow_height, cod_interval, cod_circle, flow_cal_con
			)
			values( pk_of_euid, 
				rain_wakeup_, rain_report_, norain_wakeup_, norain_report_,
				flow_pipe_, flow_height_, cod_interval_, cod_circle_, flow_cal_con_);
		end if;
	end if;
end;
$$ LANGUAGE plpgsql;


create or replace function save_spongecity_data(
	euid_ text,
	signal_ integer, sim_id_ text, voltage_ integer,
	flow_use_ integer, flow_code_ integer, ss_use_ integer, ss_code_ integer,
	cod_use_ integer, cod_code_ integer, rain_use_ integer, rain_code_ integer,
	flow_ integer, flow_all_ integer, temperature_ integer, rate_ integer, depth_ integer,
	ss_ integer, ss_factor_ double precision, humidity_ integer,
	cod_ integer, cod_turbidity_ integer, hyetal_ integer, hyetal_all_ integer
) 
returns void as $$
declare
pk_of_euid integer;
begin
    select id into pk_of_euid from t_node_info2 where euid = euid_;
    if found then
		insert into t_spongecity_data(euid, time,
		signal, sim_id, voltage,
		flow_use, flow_code, ss_use, ss_code, 
		cod_use, cod_code, rain_use, rain_code,
		flow, flow_all, temperature, rate, depth,
		ss, ss_factor, humidity,
		cod, cod_turbidity, hyetal, hyetal_all
	)
		values(
			pk_of_euid, localtimestamp,
		signal_, sim_id_, voltage_,
		flow_use_, flow_code_, ss_use_, ss_code_,
		cod_use_, cod_code_, rain_use_, rain_code_,
		flow_, flow_all_, temperature_, rate_, depth_,
		ss_, ss_factor_, humidity_,
		cod_, cod_turbidity_, hyetal_, hyetal_all_
		);
		
	end if;
end;
$$ LANGUAGE plpgsql;


